﻿<documents created="2010-12-15 11:49:35Z"><document src="C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Automaton Model\Cellular Automaton.cs" renderPrefix="s0"><chunk hits="-1" domain="unknown"><source><![CDATA[using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.Automaton_Model {
    /// <summary>
    ///   A cellular automaton consisting of an N-dimensional grid of cells.
    ///   Every new generation each cell gets a given state defined by one or more rules.
    ///   These rules consider a predefined set of neighbouring cells and hence decide a cells new state.
    ///   States are always represented using integers (discrete values).
    ///   States can be set and read via an indexer, eg. ca[0, 1] = 1;<br></br><br></br>
    ///   NOTE: Ideally this would be implemented using generics so states could also be decimals.
    ///   But due to C#'s lack of type constraint options on value types - this was omitted.<br></br><br></br>
    ///   This implementation is designed to allow a high degree of flexibility in the use of cellular automata.
    ///   Its N-dimensional and each cell may have its own state space and rule(s). Rules can use different
    ///   neighbourhoods which they process with their RuleDelegate - which again may use other delegates.
    ///   Thus this flexibility may make the overall semantics a little confusing at first.
    ///   However, one can setup a simple CA where all cells use the same space, rule and neighbourhood 
    ///   by simply using one of the constructors.
    /// </summary>
    /// <author>Anders Øland / anoe@itu.dk</author>
    [PexClass]
    [Serializable]
    public class CellularAutomaton : ICloneable {
        public uint Dimensions { get; private set; }
        public uint DimensionSize { get; private set; }
        public uint Generation { get; private set; }

        // _grid hold the cells of CA's the N-dimensional grid
        protected Cell[] Grid;

        public Rule DefaultRule { get; private set; }

        /// <summary>
        ///   Construct a new Cellular Automaton
        /// </summary>
        /// <param name = "dimensions">Number of dimensions</param>
        /// <param name = "dimensionSize">Size of the dimensions</param>
        /// <param name = "defaultRule">The default rule for all cells</param>
        /// <param name = "stateMin">default = 0</param>
        /// <param name = "stateMax">default = 1</param>
        /// <param name = "stateInit"></param>
//        [PexMethod]
        ]]></source>
</chunk>
<method name=".ctor" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" typeName="CellularAutomaton" token="60001cf" module="AutomaTones.exe"><hits><hit index="0" value="2"/>
<hit index="1" value="2"/>
<hit index="2" value="2"/>
<hit index="3" value="2"/>
<hit index="4" value="2"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="3" total="3" coveredRatio="1"/>
</method>
<chunk hits="2" offset="0000" domain="userortestcode"><source><![CDATA[public CellularAutomaton(uint dimensions, uint dimensionSize, Rule defaultRule, int stateMin = 0,
                                 int stateMax = 1, int stateInit = 0)]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="2" offset="0007" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(0 < dimensions);
            Contract.Requires(0 < dimensionSize);
            Contract.Requires(null != defaultRule);
            Contract.Requires(dimensions == defaultRule.Dimensions);
            Contract.Requires(stateMin < stateMax);
            Contract.Requires(stateMin <= stateInit && stateMax >= stateInit);
            ]]></source>
</chunk>
<chunk hits="2" offset="0008" domain="userortestcode"><source><![CDATA[Init(dimensions, dimensionSize, defaultRule, stateMin, stateMax, stateInit);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2" offset="0018" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        private void Init(uint dimensions, uint dimensionSize, Rule defaultRule,
                          int stateMin = 0, int stateMax = 1, int stateInit = 0) ]]></source>
</chunk>
<method name="Init" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" typeName="CellularAutomaton" token="60001d0" module="AutomaTones.exe"><hits><hit index="0" value="2"/>
<hit index="1" value="2"/>
<hit index="2" value="2"/>
<hit index="3" value="2"/>
<hit index="4" value="2"/>
<hit index="5" value="2"/>
<hit index="6" value="2"/>
<hit index="7" value="2"/>
<hit index="8" value="2"/>
<hit index="9" value="2"/>
<hit index="10" value="2"/>
<hit index="11" value="2"/>
<hit index="12" value="2"/>
<hit index="14" value="2"/>
<hit index="15" value="2"/>
<hit index="16" value="2"/>
<hit index="17" value="2"/>
<hit index="18" value="116"/>
<hit index="19" value="116"/>
<hit index="21" value="116"/>
<hit index="22" value="116"/>
<hit index="23" value="116"/>
<hit index="24" value="116"/>
<hit index="25" value="116"/>
<hit index="26" value="118"/>
<hit index="27" value="118"/>
<hit index="28" value="2"/>
<hit index="29" value="2"/>
<hit index="30" value="2"/>
<hit index="31" value="116"/>
</hits>
<tags><tag offset="002a">call to external method Math.Pow(Double, Double)</tag>
</tags>
<coverage domain="userortestcode" unit="block" covered="11" total="11" coveredRatio="1"/>
</method>
<chunk hits="2" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(0 < dimensions && 0 < dimensionSize);
            Contract.Requires(dimensions == defaultRule.Dimensions);
            Contract.Requires(stateMin < stateMax);
            Contract.Requires(stateMin <= stateInit && stateMax >= stateInit);
            ]]></source>
</chunk>
<chunk hits="2" offset="0001" domain="userortestcode"><source><![CDATA[Generation = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2" offset="0009" domain="userortestcode"><source><![CDATA[Dimensions = dimensions;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2" offset="0011" domain="userortestcode"><source><![CDATA[DimensionSize = dimensionSize;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2" offset="0019" domain="userortestcode" tag="true"><tooltip><![CDATA[call to external method Math.Pow(Double, Double)]]></tooltip>
<source><![CDATA[Grid = new Cell[(int)Math.Pow(DimensionSize, Dimensions)];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            for (]]></source>
</chunk>
<chunk hits="4" offset="003a" domain="userortestcode"><source><![CDATA[int i = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="468" offset="0058" domain="userortestcode"><source><![CDATA[i < Grid.Length]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="464" offset="0054" domain="userortestcode"><source><![CDATA[i++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="116" offset="003e" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="116" offset="003f" domain="userortestcode"><source><![CDATA[Grid[i] = new Cell(defaultRule, stateMin, stateMax, stateInit);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="464" offset="0053" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2" offset="0067" domain="userortestcode"><source><![CDATA[DefaultRule = defaultRule;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2" offset="006f" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Finds the right cell in the N-dimensional grid in the one dimensional array holding the cells
        /// </summary>
        [PexMethod]
        [Pure] // Tagged as pure since its being called from other contracts which I dont want to loosen 
        protected internal virtual Cell GetCell(params int[] coord) ]]></source>
</chunk>
<method name="GetCell" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" typeName="CellularAutomaton" token="60001d1" module="AutomaTones.exe"><hits><hit index="0" value="9673"/>
<hit index="1" value="9673"/>
<hit index="2" value="9673"/>
<hit index="3" value="9673"/>
<hit index="4" value="9673"/>
<hit index="5" value="9673"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="2" total="2" coveredRatio="1"/>
</method>
<chunk hits="9673" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != coord);
            Contract.Requires(coord.Length == Dimensions);
            Contract.Ensures(Contract.Result<Cell>() != null);
            ]]></source>
</chunk>
<chunk hits="9673" offset="0001" domain="userortestcode"><source><![CDATA[uint index = GetIndex(coord);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="9673" offset="0009" domain="userortestcode"><source><![CDATA[return Grid[index];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="19346" offset="0015" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Translates a coordinate into an index number pointing to the corresponing location in the grid array.
        ///   Coordinates exceeding the bounds of the grid are 'wrapped around', 
        ///   thus giving the grid a so-called torus shape.
        /// </summary>
        [Pure]
        protected uint GetIndex(int[] coord) ]]></source>
</chunk>
<method name="GetIndex" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" typeName="CellularAutomaton" token="60001d2" module="AutomaTones.exe"><hits><hit index="0" value="9673"/>
<hit index="1" value="9673"/>
<hit index="2" value="9673"/>
<hit index="3" value="9673"/>
<hit index="4" value="9673"/>
<hit index="5" value="9673"/>
<hit index="6" value="9673"/>
<hit index="7" value="9673"/>
<hit index="8" value="9673"/>
<hit index="9" value="9673"/>
<hit index="10" value="9673"/>
<hit index="11" value="9673"/>
<hit index="12" value="108"/>
<hit index="13" value="108"/>
<hit index="14" value="108"/>
<hit index="15" value="9673"/>
<hit index="16" value="9673"/>
<hit index="17" value="9673"/>
<hit index="18" value="9673"/>
<hit index="19" value="9673"/>
<hit index="20" value="9673"/>
<hit index="21" value="19346"/>
<hit index="22" value="19346"/>
<hit index="23" value="9673"/>
<hit index="25" value="9565"/>
<hit index="26" value="9673"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="13" total="14" coveredRatio="0.9285714285714286"/>
</method>
<chunk hits="9673" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != coord);
            Contract.Requires(0 < DimensionSize && 0 < Dimensions);
            Contract.Requires(coord.Length == Dimensions);
            Contract.Ensures((uint)Math.Pow(DimensionSize, Dimensions) > Contract.Result<uint>());
            ]]></source>
</chunk>
<chunk hits="9673" offset="0001" domain="userortestcode"><source><![CDATA[var index = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            for (]]></source>
</chunk>
<chunk hits="9673" offset="0003" domain="userortestcode"><source><![CDATA[int i = 1;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="19346" offset="0060" domain="userortestcode"><source><![CDATA[i <= Dimensions]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="9673" offset="005c" domain="userortestcode"><source><![CDATA[i++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="9673" offset="0007" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                // Loop invariant
                ]]></source>
</chunk>
<chunk hits="9673" offset="0008" domain="userortestcode"><source><![CDATA[Contract.Assert(0 <= index && Grid.Length > index);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                // Make sure coordinates which exceed the bounds of any dimension are 'wrapped around'
                ]]></source>
</chunk>
<chunk hits="9673" offset="0020" domain="userortestcode"><source><![CDATA[int c = coord[i - 1] % (int)DimensionSize;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="19346" offset="002d" domain="userortestcode"><source><![CDATA[c = 0 <= c ? c : c + (int)DimensionSize;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                // Sum the the effect of each coordinate to find the correct position in the grid array
                ]]></source>
</chunk>
<chunk hits="9673" offset="003d" domain="userortestcode"><source><![CDATA[index += c * (int)Math.Pow(DimensionSize, Dimensions - i);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="9673" offset="005b" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="9673" offset="0074" domain="userortestcode"><source><![CDATA[return (uint)index;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="9673" offset="0078" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Translates an index number into a coordinate.
        /// </summary>
        /// <param name = "index"></param>
        /// <returns></returns>
        private int[] GetCoordinate(uint index) ]]></source>
</chunk>
<method name="GetCoordinate" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" typeName="CellularAutomaton" token="60001d3" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
<hit index="2" value="2400"/>
<hit index="3" value="2400"/>
<hit index="4" value="2400"/>
<hit index="5" value="2400"/>
<hit index="6" value="2400"/>
<hit index="7" value="2400"/>
<hit index="8" value="2400"/>
<hit index="9" value="2400"/>
<hit index="10" value="2400"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="6" total="6" coveredRatio="1"/>
</method>
<chunk hits="2400" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(index < Grid.Length);
            Contract.Ensures(Dimensions == Contract.Result<int[]>().Length);
            // As long as the grid is rectangular (not jagged) this is equivalent to converting
            // index from base 10 to base DimensionSize.
            ]]></source>
</chunk>
<chunk hits="2400" offset="0001" domain="userortestcode"><source><![CDATA[return Tools.Math.DecimalToBase(index, DimensionSize, Dimensions).Reverse().ToArray();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2400" offset="0020" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Returns the State Object of the cell.
        /// </summary>
        /// <param name = "coord"></param>
        /// <returns>The state of the cell with the given coordinates</returns>
        public State GetCellState(params int[] coord) {
            Contract.Requires(coord.Length == Dimensions);
            Contract.Ensures(Contract.Result<State>() != null);
            return GetCell(coord).State;
        }

        /// <summary>
        ///   Returns the rule of the cell with the given coordinates.
        ///   Note that one rule may consist of many rules.
        /// </summary>
        /// <param name = "coord">Coordinates</param>
        /// <returns>IRule</returns>
        [PexMethod]
        public Rule GetCellRule(params int[] coord) {
            Contract.Requires(coord.Length == Dimensions);
            Contract.Ensures(Contract.Result<Rule>() != null);
            return GetCell(coord).Rule;
        }

        /// <summary>
        ///   Sets the rule of the cell with the given coordinates.
        /// </summary>
        /// <param name = "rule"></param>
        /// <param name = "coord">Coordinates</param>
        public void SetCellRule(Rule rule, params int[] coord) {
            Contract.Requires(coord.Length == Dimensions);
            Contract.Requires(rule != null);
            GetCell(coord).Rule = rule;
        }

        /// <summary>
        ///   Add a trigger to the cell with the given coordinates.
        /// </summary>
        /// <param name = "trigger">Trigger</param>
        /// <param name = "coord">int[]</param>
        public void AddTrigger(Trigger trigger, params int[] coord) {
            Contract.Requires(coord.Length == Dimensions);
            Contract.Requires(trigger != null);
            Contract.Ensures(GetCell(coord).Triggers.Contains(trigger));
            GetCell(coord).Triggers.Add(trigger);
        }

        /// <summary>
        ///   Removes the trigger from the cell with the given coodinates.
        /// </summary>
        /// <param name = "trigger">Trigger</param>
        /// <param name = "coord">coordinates</param>
        public void RemoveTrigger(Trigger trigger, params int[] coord) {
            Contract.Requires(coord.Length == Dimensions);
            Contract.Requires(trigger != null);
            Contract.Ensures(!GetCell(coord).Triggers.Contains(trigger));
            GetCell(coord).Triggers.Remove(trigger);
        }

        /// <summary>
        ///   Evolve this Cellular Automaton - move one generation forward
        ///   by applying the rule(s) to the cells.
        /// </summary>
        public virtual void Evolve() ]]></source>
</chunk>
<method name="Evolve" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" typeName="CellularAutomaton" token="60001d9" module="AutomaTones.exe"><hits><hit index="0" value="108"/>
<hit index="1" value="2400"/>
<hit index="2" value="2400"/>
<hit index="3" value="2400"/>
<hit index="4" value="2400"/>
<hit index="5" value="2400"/>
<hit index="6" value="2400"/>
<hit index="7" value="4800"/>
<hit index="8" value="2400"/>
<hit index="9" value="2400"/>
<hit index="10" value="2400"/>
<hit index="11" value="2400"/>
<hit index="12" value="2400"/>
<hit index="13" value="2400"/>
<hit index="14" value="4800"/>
<hit index="15" value="2400"/>
<hit index="16" value="2400"/>
<hit index="18" value="2400"/>
<hit index="19" value="2400"/>
<hit index="20" value="2400"/>
<hit index="21" value="2400"/>
<hit index="22" value="2400"/>
<hit index="23" value="4800"/>
<hit index="24" value="2400"/>
<hit index="25" value="2400"/>
<hit index="26" value="2400"/>
<hit index="27" value="4800"/>
<hit index="28" value="2508"/>
<hit index="29" value="2508"/>
<hit index="30" value="108"/>
<hit index="31" value="108"/>
<hit index="32" value="2400"/>
<hit index="33" value="2400"/>
<hit index="34" value="2400"/>
<hit index="35" value="2400"/>
<hit index="36" value="2400"/>
<hit index="37" value="4800"/>
<hit index="38" value="2400"/>
<hit index="39" value="2400"/>
<hit index="40" value="2400"/>
<hit index="41" value="4800"/>
<hit index="42" value="2400"/>
<hit index="43" value="2400"/>
<hit index="44" value="2400"/>
<hit index="45" value="4800"/>
<hit index="46" value="2400"/>
<hit index="47" value="2400"/>
<hit index="48" value="2400"/>
<hit index="49" value="4800"/>
<hit index="50" value="2508"/>
<hit index="51" value="108"/>
<hit index="52" value="108"/>
<hit index="53" value="108"/>
<hit index="54" value="108"/>
<hit index="55" value="108"/>
<hit index="56" value="2400"/>
<hit index="57" value="2400"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="16" total="16" coveredRatio="1"/>
</method>
<chunk hits="108" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Ensures(Generation == Contract.OldValue(Generation) + 1);
            Contract.Ensures(Contract.ForAll(0, Grid.Length,
                                             i => Grid[i].State.CurrentState == Grid[i].State.NextState));
            // Calculate new states from current states
            for (]]></source>
</chunk>
<chunk hits="108" offset="0001" domain="userortestcode"><source><![CDATA[uint index = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="7308" offset="003e" domain="userortestcode"><source><![CDATA[index < Grid.Length]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="7200" offset="003a" domain="userortestcode"><source><![CDATA[index++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[)
                ]]></source>
</chunk>
<chunk hits="2400" offset="0005" domain="userortestcode"><source><![CDATA[Grid[index].State.NextState = Grid[index].Rule.ApplyRule(GetCoordinate(index), this);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

            // Commit new states
            ]]></source>
</chunk>
<chunk hits="108" offset="004f" domain="userortestcode"><source><![CDATA[foreach]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ (]]></source>
</chunk>
<chunk hits="2400" offset="005c" domain="userortestcode"><source><![CDATA[Cell cell]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="7308" offset="007e" domain="userortestcode"><source><![CDATA[in]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="108" offset="0050" domain="userortestcode"><source><![CDATA[Grid]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="4800" offset="0061" domain="userortestcode"><source><![CDATA[cell.State.CurrentState = cell.State.NextState;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="108" offset="0089" domain="userortestcode"><source><![CDATA[Generation++;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="108" offset="0098" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Indexer for the CA's grid of cells.
        /// </summary>
        /// <param name = "coord">coordinate</param>
        /// <returns>Cell at the given coordinate</returns>
        public virtual int this[params int[] coord] {
            get {
                Contract.Requires(coord.Length == Dimensions);
                return GetCell(coord).State.CurrentState;
            }
            set {
                Contract.Requires(coord.Length == Dimensions);
                Contract.Ensures(GetCell(coord).State.CurrentState.Equals(value));
                Grid[GetIndex(coord)].State.CurrentState = value;
            }
        }

        /// <summary>
        ///   For iterating over the entire grid.
        /// </summary>
        /// <returns></returns>
        [Pure]
        public IEnumerable<int> GridEnumerator() {
            return Grid.Select(cell => cell.State.CurrentState);
        }

        /// <summary>
        /// Returns a copy of the cellular automatons current grid of cells.
        /// </summary>
        /// <returns></returns>
        public Cell[] CopyOfGrid() {
            Contract.Ensures(Contract.ForAll(0, Grid.Length, i => Grid[i] == Contract.Result<Cell[]>()[i]));
            Cell[] copy = new Cell[Grid.Length];
            for (int i = 0; i < Grid.Length; i++) {
                Cell c = Grid[i];
                copy[i] = new Cell(c.Rule, c.State.SpaceMin, c.State.SpaceMax, c.State.CurrentState);
            }
            return copy;
        }

        [ContractInvariantMethod]
        // ReSharper disable UnusedMember.Local
        private void ObjInvar() {
            // ReSharper restore UnusedMember.Local
            Contract.Invariant(0 <= Generation);
            Contract.Invariant(0 < DimensionSize);
            Contract.Invariant(0 < Dimensions);
            Contract.Invariant(Grid.Length == (int)Math.Pow((double)DimensionSize, (double)Dimensions));
            Contract.Invariant(Contract.ForAll(Grid, c => null != c));
            Contract.Invariant(null != DefaultRule);
        }

        public override
            string ToString() {
            String s = "", t = "";
            foreach (int i in GridEnumerator()) {
                s += i;
                if (s.Length < 1 * DimensionSize) continue;
                t += s + "\n";
                s = "";
            }
            return t;
        }

        public object Clone() {
            return new CellularAutomaton(Dimensions, DimensionSize, DefaultRule) {
                Generation = Generation,
                Grid = CopyOfGrid()
            };
        }
    }

    /// <author>Anders Øland / anoe@itu.dk</author>
    /// <summary>
    /// A specialized Cellular Automaton for Wolfram one-dimensional automata.
    /// The grid does not have a torus shape (coordinates are not 'wrapper around'), instead the actual size of the grid is in fact
    /// larger than the specified size - so borderline cells can be processed.
    /// </summary>
    public class WolframAutomaton : CellularAutomaton {
        public uint ViewedSize { get; private set; }
        private readonly Cell[,] _viewedGrid;

        /// <summary>
        /// Create a new WolframAutomaton.
        /// </summary>
        /// <param name="wolframRule"></param>
        /// <param name="stateSpace">size of the state space, 2 = binary</param>
        /// <param name="viewedSize">size of the rectangular grid displaying the CA</param>
        /// <param name="actualSize">actual size of the CA in memmory</param>
        ]]></source>
</chunk>
<method name=".ctor" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.WolframAutomaton" typeName="WolframAutomaton" token="60001e4" module="AutomaTones.exe"><hits><hit index="0" value="1"/>
<hit index="1" value="1"/>
<hit index="2" value="1"/>
<hit index="3" value="1"/>
<hit index="4" value="1"/>
<hit index="5" value="1"/>
<hit index="6" value="1"/>
<hit index="7" value="1"/>
<hit index="8" value="1"/>
<hit index="9" value="1"/>
<hit index="11" value="1"/>
<hit index="12" value="1"/>
<hit index="13" value="1"/>
<hit index="14" value="1"/>
<hit index="16" value="1"/>
<hit index="17" value="1"/>
<hit index="18" value="1"/>
<hit index="19" value="1"/>
<hit index="20" value="1"/>
<hit index="21" value="1"/>
<hit index="22" value="1"/>
<hit index="23" value="1"/>
<hit index="24" value="1"/>
<hit index="25" value="1"/>
<hit index="26" value="1"/>
<hit index="27" value="2"/>
<hit index="28" value="1"/>
<hit index="29" value="1"/>
<hit index="30" value="1"/>
<hit index="31" value="2"/>
<hit index="32" value="1"/>
<hit index="33" value="1"/>
<hit index="34" value="8"/>
<hit index="35" value="8"/>
<hit index="36" value="8"/>
<hit index="37" value="16"/>
<hit index="38" value="1"/>
<hit index="39" value="8"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="12" total="12" coveredRatio="1"/>
</method>
<chunk hits="1" offset="0000" domain="userortestcode"><source><![CDATA[public WolframAutomaton(Rule wolframRule, int stateSpace, uint viewedSize = 64u, uint actualSize = 100u)
            : base(1, actualSize, wolframRule, 0, stateSpace - 1)]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="1" offset="0010" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(3 <= viewedSize);
            Contract.Requires(viewedSize <= actualSize);
            Contract.Requires(null != wolframRule);
            Contract.Requires(1 < stateSpace);
            ]]></source>
</chunk>
<chunk hits="1" offset="0011" domain="userortestcode"><source><![CDATA[ViewedSize = viewedSize;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="0019" domain="userortestcode"><source><![CDATA[_viewedGrid = new Cell[ViewedSize, ViewedSize];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2" offset="0032" domain="userortestcode"><source><![CDATA[base.GetCell((int)(actualSize / 2)).State.CurrentState = 1;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="3" offset="0053" domain="userortestcode"><source><![CDATA[UpdateViewedGrid();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            for (]]></source>
</chunk>
<chunk hits="1" offset="005a" domain="userortestcode"><source><![CDATA[int i = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="25" offset="0069" domain="userortestcode"><source><![CDATA[i < viewedSize]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="24" offset="0065" domain="userortestcode"><source><![CDATA[i++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="8" offset="005e" domain="userortestcode"><source><![CDATA[Evolve();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="1" offset="0073" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Returns a cell from the viewed two-dimensional grid.
        /// </summary>
        protected internal new Cell GetCell(params int[] coord) {
            Contract.Requires(coord.Length == 2);
            Contract.Ensures(Contract.Result<Cell>() != null);
            return _viewedGrid[coord[0], coord[1]];
        }

        public override sealed void Evolve() ]]></source>
</chunk>
<method name="Evolve" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.WolframAutomaton" typeName="WolframAutomaton" token="60001e6" module="AutomaTones.exe"><hits><hit index="0" value="8"/>
<hit index="1" value="8"/>
<hit index="2" value="8"/>
<hit index="3" value="8"/>
<hit index="4" value="8"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="3" total="3" coveredRatio="1"/>
</method>
<chunk hits="8" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="8" offset="0001" domain="userortestcode"><source><![CDATA[base.Evolve();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="8" offset="0008" domain="userortestcode"><source><![CDATA[UpdateViewedGrid();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="8" offset="000f" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        private void UpdateViewedGrid() ]]></source>
</chunk>
<method name="UpdateViewedGrid" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.WolframAutomaton" typeName="WolframAutomaton" token="60001e7" module="AutomaTones.exe"><hits><hit index="0" value="9"/>
<hit index="1" value="504"/>
<hit index="2" value="504"/>
<hit index="3" value="504"/>
<hit index="4" value="504"/>
<hit index="5" value="504"/>
<hit index="6" value="504"/>
<hit index="7" value="504"/>
<hit index="8" value="504"/>
<hit index="9" value="504"/>
<hit index="10" value="576"/>
<hit index="11" value="576"/>
<hit index="12" value="72"/>
<hit index="13" value="72"/>
<hit index="14" value="72"/>
<hit index="15" value="72"/>
<hit index="16" value="72"/>
<hit index="17" value="72"/>
<hit index="19" value="72"/>
<hit index="20" value="72"/>
<hit index="21" value="72"/>
<hit index="22" value="72"/>
<hit index="23" value="72"/>
<hit index="24" value="72"/>
<hit index="25" value="72"/>
<hit index="26" value="72"/>
<hit index="27" value="72"/>
<hit index="28" value="72"/>
<hit index="29" value="72"/>
<hit index="30" value="72"/>
<hit index="31" value="72"/>
<hit index="32" value="72"/>
<hit index="33" value="72"/>
<hit index="34" value="72"/>
<hit index="35" value="72"/>
<hit index="36" value="72"/>
<hit index="37" value="81"/>
<hit index="38" value="81"/>
<hit index="39" value="9"/>
<hit index="40" value="504"/>
<hit index="41" value="72"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="11" total="11" coveredRatio="1"/>
</method>
<chunk hits="9" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(ViewedSize <= DimensionSize);
            Contract.Requires(null != _viewedGrid);
            Contract.Requires(null != Grid);
            for (]]></source>
</chunk>
<chunk hits="9" offset="0001" domain="userortestcode"><source><![CDATA[int y = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="225" offset="0080" domain="userortestcode"><source><![CDATA[y < ViewedSize]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="216" offset="007c" domain="userortestcode"><source><![CDATA[y++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="72" offset="0005" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                // Shift left
                for (]]></source>
</chunk>
<chunk hits="72" offset="0006" domain="userortestcode"><source><![CDATA[int x = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="1584" offset="002a" domain="userortestcode"><source><![CDATA[x < ViewedSize - 1]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="1512" offset="0026" domain="userortestcode"><source><![CDATA[x++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="504" offset="000a" domain="userortestcode"><source><![CDATA[_viewedGrid[x, y] = _viewedGrid[x + 1, y];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                // Add new generation
                ]]></source>
</chunk>
<chunk hits="72" offset="003b" domain="userortestcode"><source><![CDATA[_viewedGrid[ViewedSize - 1, y] = base.GetCell((int)(ViewedSize / 2 - y + (int)DimensionSize / 2));]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="216" offset="007b" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="9" offset="0092" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
    }
}]]></source>
</chunk>
</document>
<document src="C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Automaton Model\AutomaTest\WolframTestScenario.cs" renderPrefix="s1"><chunk hits="-1" domain="unknown"><source><![CDATA[using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutomaTones.Model.Automaton_Model;
using AutomaTones.Model.Automaton_Model.RuleLib;
using Microsoft.Pex.Framework;

namespace AutomaTones {
    /// <author>Anders Øland / anoe@itu.dk</author>
    /// <summary>
    /// Test scenarios for the Wolfram automaton.
    /// Most relevant usages should be covered by the tests. 
    /// </summary>
    [PexClass]
    partial class WolframTestScenario {
        [PexMethod(MaxBranches = 1500000)]
        public void TestWolframCA() ]]></source>
</chunk>
<method name="TestWolframCA" namespace="AutomaTones" type="AutomaTones.WolframTestScenario" typeName="WolframTestScenario" token="600021d" module="AutomaTones.exe"><hits><hit index="0" value="1"/>
<hit index="1" value="1"/>
<hit index="2" value="1"/>
<hit index="3" value="1"/>
<hit index="4" value="1"/>
<hit index="6" value="1"/>
<hit index="7" value="1"/>
<hit index="8" value="1"/>
<hit index="9" value="1"/>
<hit index="10" value="1"/>
<hit index="11" value="1"/>
<hit index="12" value="1"/>
<hit index="14" value="1"/>
<hit index="15" value="1"/>
<hit index="16" value="1"/>
<hit index="18" value="1"/>
<hit index="19" value="1"/>
<hit index="20" value="1"/>
<hit index="21" value="1"/>
<hit index="22" value="1"/>
<hit index="23" value="1"/>
<hit index="24" value="1"/>
<hit index="25" value="1"/>
<hit index="26" value="1"/>
<hit index="27" value="1"/>
<hit index="28" value="100"/>
<hit index="29" value="100"/>
<hit index="30" value="100"/>
<hit index="31" value="200"/>
<hit index="32" value="1"/>
<hit index="33" value="100"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="9" total="9" coveredRatio="1"/>
</method>
<chunk hits="1" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="0001" domain="userortestcode"><source><![CDATA[WolframAutomata.NewPatternRule(WolframAutomata.WolframCode(90), 2);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="0011" domain="userortestcode"><source><![CDATA[WolframAutomata.NewPatternRule(new[] { 0, 1, 1, 0, 0, 1, 1, 1, 1 }, 2);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="002a" domain="userortestcode"><source><![CDATA[WolframAutomata.NewWolframAutomaton(8, 90, 2);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="0034" domain="userortestcode"><source><![CDATA[CellularAutomaton w = WolframAutomata.NewPatternAutomaton(16, new[] { 0, 1, 1, 0, 0, 1, 1, 1, 1 },
                            new[] { 0, 1, 1 }, 3, 2);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            for (]]></source>
</chunk>
<chunk hits="1" offset="0060" domain="userortestcode"><source><![CDATA[int i = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="301" offset="0071" domain="userortestcode"><source><![CDATA[i < 100]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="300" offset="006d" domain="userortestcode"><source><![CDATA[i++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="100" offset="0064" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="100" offset="0065" domain="userortestcode"><source><![CDATA[w.Evolve();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="300" offset="006c" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="1" offset="007a" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
    }
}
]]></source>
</chunk>
</document>
<document src="C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Automaton Model\RuleLib\WolframAutomata.cs" renderPrefix="s2"><chunk hits="-1" domain="unknown"><source><![CDATA[using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.Automaton_Model.RuleLib {
    /// <author>Anders Øland / anoe@itu</author>
    /// <summary>
    /// Provides the rule used for the Wolfram Automatons - or any other pattern-based rule-type cellular automaton.
    /// <br></br><br></br>
    /// This class also facilitates easy setup of Wolfram/pattern-based CA. 
    /// </summary>
    [PexClass]
    public static partial class WolframAutomata {
        /// <summary>
        /// This rule is intended for use with Wolfram one-dimensional automata -
        /// or any other pattern-based rule-type cellular automaton.
        /// The state space may have any size - but MUST be shared by all cells, and the lower bound MUST be zero - 
        /// and the grid can be N-dimensional.
        /// <br></br><br></br>
        /// The rule is represented by a Wolfram code; 
        /// range 0 to S^S^(2n+1) - 1 where S = size of the state space, n = size of the neighbourhood.
        /// Eg. a Wolfram Code for a binary rule based on two neighbours:<br></br>
        /// Pattern 1: 00 --> new state 0<br></br>
        /// Pattern 2: 01 --> new state 1<br></br>
        /// Pattern 3: 10 --> new state 0<br></br>
        /// Pattern 4: 11 --> new state 1<br></br>
        /// The code number is the binary number formed by the state column: %1010
        /// ==> Rule number 10 (decimal). <br></br><br></br>
        /// Thus when eg. pattern 4 is parsed to this rule ==> it returns bit 4 of the Wolfram code.<br></br><br></br>
        /// NOTE: 8 neighbours and 8 possible states ==> 8^8^17 - 1 possible rules(!!!) and ulong.MaxValue = 2^64 -1. 
        /// Thus, not all possible rules can be used!
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="statesOfNeighbours"></param>
        /// <param name="wolframCode">MUST be less than 2^64</param>
        /// <returns></returns>
        public static int WolframRule(Cell cell, ref IEnumerable<Rule.StateAtCoordinate> statesOfNeighbours,
                                      int[] wolframCode) ]]></source>
</chunk>
<method name="WolframRule" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="6000066" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
<hit index="3" value="2400"/>
<hit index="4" value="2400"/>
<hit index="5" value="2400"/>
<hit index="6" value="2400"/>
<hit index="7" value="1"/>
<hit index="8" value="1"/>
<hit index="10" value="1"/>
<hit index="11" value="2400"/>
<hit index="12" value="2400"/>
<hit index="13" value="2400"/>
<hit index="14" value="2400"/>
<hit index="15" value="2400"/>
<hit index="16" value="2400"/>
<hit index="17" value="2400"/>
<hit index="18" value="2400"/>
<hit index="19" value="4800"/>
<hit index="20" value="2400"/>
<hit index="21" value="2400"/>
<hit index="22" value="2400"/>
<hit index="23" value="4800"/>
<hit index="24" value="2400"/>
<hit index="25" value="2400"/>
<hit index="26" value="2400"/>
<hit index="27" value="2400"/>
<hit index="28" value="4800"/>
<hit index="29" value="2400"/>
<hit index="30" value="2400"/>
<hit index="31" value="2400"/>
<hit index="32" value="4800"/>
<hit index="33" value="2400"/>
<hit index="34" value="2400"/>
<hit index="35" value="2400"/>
<hit index="36" value="2400"/>
<hit index="37" value="2399"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="12" total="12" coveredRatio="1"/>
</method>
<chunk hits="4800" offset="000d" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != cell);
            Contract.Requires(0 == cell.State.SpaceMin && 0 < cell.State.SpaceMax);
            Contract.Requires(Contract.ForAll(statesOfNeighbours, sn => 1 == sn.Position.Coord.Length));
            Contract.Requires(Contract.ForAll(statesOfNeighbours, sn => cell.State.SpaceMin <= sn.State
                                                                        && cell.State.SpaceMax >= sn.State));
            Contract.Ensures(cell.State.SpaceMin <= Contract.Result<int>());
            Contract.Ensures(cell.State.SpaceMax >= Contract.Result<int>());
            // Find the bit(or digit) number representing this pattern in the Wolfram Code for the chosen rule.
            ]]></source>
</chunk>
<chunk hits="4800" offset="000e" domain="userortestcode"><source><![CDATA[var bit = Tools.Math.BaseToDecimal((from n in statesOfNeighbours select ]]></source>
</chunk>
<method name="&lt;WolframRule&gt;b__0" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="600006f" module="AutomaTones.exe"><hits><hit index="0" value="7200"/>
<hit index="1" value="7200"/>
<hit index="2" value="7200"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="2" total="2" coveredRatio="1"/>
</method>
<chunk hits="7200" offset="0000" domain="userortestcode"><source><![CDATA[n.State]]></source>
</chunk>
<chunk hits="4800" offset="000e" domain="userortestcode"><source><![CDATA[).ToArray(),
                                               (uint) (cell.State.SpaceMax - cell.State.SpaceMin + 1));]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2400" offset="0062" domain="userortestcode"><source><![CDATA[return wolframCode[bit];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="4800" offset="0069" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Converts a Wolfram Code from decimal to any base( = the amount of possible states).
        /// The resulting array will have the length required to represent 2^64 - 1 in the given base.
        /// </summary>
        /// <param name="wolframCode">Decimal representation</param>
        /// <param name="stateSpace">The amount of possible states</param>
        /// <returns>Base[statespace] representation of the code by array of digits</returns>
        public static int[] WolframCode(ulong wolframCode, uint stateSpace = 2u) ]]></source>
</chunk>
<method name="WolframCode" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="6000067" module="AutomaTones.exe"><hits><hit index="0" value="2"/>
<hit index="1" value="2"/>
<hit index="2" value="2"/>
<hit index="3" value="2"/>
<hit index="4" value="2"/>
<hit index="5" value="2"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="3" total="3" coveredRatio="1"/>
</method>
<chunk hits="2" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(1 < stateSpace);
            Contract.Ensures(Tools.Math.DecimalToBase(ulong.MaxValue, stateSpace).Length >=
                             Contract.Result<int[]>().Length);
            ]]></source>
</chunk>
<chunk hits="2" offset="0001" domain="userortestcode"><source><![CDATA[var digits = Tools.Math.DecimalToBase(ulong.MaxValue, stateSpace).Length;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2" offset="000d" domain="userortestcode"><source><![CDATA[return Tools.Math.DecimalToBase(wolframCode, stateSpace, (uint) digits);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2" offset="0018" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Converts a series of rule patterns into a Wolfram Code represented by an array of digits.
        /// The array will have the lenght needed to represent 2^64 -1 (ulong.MaxValue) in base[stateSpace]
        /// </summary>
        /// <param name="patterns">All the patterns included in the rule - concatenated in one array</param>
        /// <param name="states">List of the states which each pattern map to</param>
        /// <param name="numOfNeighbours">The size of the neighbourhood used by the intended rule</param>
        /// <param name="stateSpace">Amount of possible states</param>
        /// <returns>Base[statespace] representation of the code by array of digits</returns>
        public static int[] WolframCode(int[] patterns, int[] states, uint numOfNeighbours = 3u, uint stateSpace = 2u) ]]></source>
</chunk>
<method name="WolframCode" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="6000068" module="AutomaTones.exe"><hits><hit index="0" value="1"/>
<hit index="1" value="1"/>
<hit index="2" value="1"/>
<hit index="3" value="1"/>
<hit index="5" value="1"/>
<hit index="6" value="1"/>
<hit index="7" value="3"/>
<hit index="8" value="3"/>
<hit index="9" value="3"/>
<hit index="10" value="3"/>
<hit index="11" value="1"/>
<hit index="12" value="1"/>
<hit index="14" value="1"/>
<hit index="15" value="3"/>
<hit index="16" value="3"/>
<hit index="17" value="3"/>
<hit index="18" value="3"/>
<hit index="19" value="3"/>
<hit index="20" value="3"/>
<hit index="21" value="3"/>
<hit index="22" value="3"/>
<hit index="23" value="3"/>
<hit index="24" value="3"/>
<hit index="25" value="3"/>
<hit index="26" value="4"/>
<hit index="27" value="4"/>
<hit index="28" value="4"/>
<hit index="29" value="1"/>
<hit index="30" value="2"/>
<hit index="31" value="3"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="12" total="12" coveredRatio="1"/>
</method>
<chunk hits="1" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(1 < stateSpace);
            Contract.Requires(0 == patterns.Length % numOfNeighbours);
            Contract.Requires(numOfNeighbours == states.Length);
            Contract.Ensures(Tools.Math.DecimalToBase(ulong.MaxValue, stateSpace).Length >=
                             Contract.Result<int[]>().Length);
            ]]></source>
</chunk>
<chunk hits="1" offset="0001" domain="userortestcode"><source><![CDATA[var digits = Tools.Math.DecimalToBase(ulong.MaxValue, stateSpace).Length;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="000d" domain="userortestcode"><source><![CDATA[int[] code = new int[digits];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            for (]]></source>
</chunk>
<chunk hits="1" offset="0014" domain="userortestcode"><source><![CDATA[int i = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="10" offset="0067" domain="userortestcode"><source><![CDATA[i < patterns.Length / numOfNeighbours]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="9" offset="0063" domain="userortestcode"><source><![CDATA[i++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="3" offset="0018" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="3" offset="0019" domain="userortestcode"><source><![CDATA[int[] pattern = (from x in patterns
                                     .Skip(i * (int) numOfNeighbours)
                                     .Take((int) numOfNeighbours)
                                 select ]]></source>
</chunk>
<method name="&lt;WolframCode&gt;b__4" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="6000070" module="AutomaTones.exe"><hits><hit index="0" value="9"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="9" offset="0000" domain="userortestcode"><source><![CDATA[x]]></source>
</chunk>
<chunk hits="3" offset="0019" domain="userortestcode"><source><![CDATA[).ToArray();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="3" offset="0052" domain="userortestcode"><source><![CDATA[var digit = (int) Tools.Math.BaseToDecimal(pattern, stateSpace);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="3" offset="005b" domain="userortestcode"><source><![CDATA[code[digit] = states[i];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="9" offset="0062" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="0078" domain="userortestcode"><source><![CDATA[return code;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="1" offset="007d" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Creates a Wolfram Automaton (one-dimensional)
        /// </summary>
        /// <param name="viewedSize">view-grid size</param>
        /// <param name="ruleNumber">The rule number (wolfram code) to be used: 0-255</param>
        /// <param name="stateSpace">size of the state space, 2 = binary</param>
        /// <returns></returns>
        public static CellularAutomaton NewWolframAutomaton(uint viewedSize, uint ruleNumber, uint stateSpace = 2u) ]]></source>
</chunk>
<method name="NewWolframAutomaton" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="6000069" module="AutomaTones.exe"><hits><hit index="0" value="1"/>
<hit index="1" value="1"/>
<hit index="2" value="1"/>
<hit index="3" value="1"/>
<hit index="4" value="1"/>
<hit index="5" value="1"/>
<hit index="7" value="1"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="4" total="4" coveredRatio="1"/>
</method>
<chunk hits="1" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(3 <= viewedSize);
            Contract.Requires(2 <= stateSpace);
            Contract.Requires(256 > ruleNumber);
            ]]></source>
</chunk>
<chunk hits="1" offset="0001" domain="userortestcode"><source><![CDATA[Rule wolframRule = NewWolframRule(WolframCode(ruleNumber));]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="0010" domain="userortestcode"><source><![CDATA[return new WolframAutomaton(wolframRule, (int) stateSpace, viewedSize);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="1" offset="001d" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Creates a Wolfram Automaton (one-dimensional) instance, based on the given patterns and corresponding states.
        /// </summary>
        /// <param name="viewedSize">view-grid size</param>
        /// <param name="patterns">the patterns of the rule concatenated into one array</param>
        /// <param name="states">the states correlating to each of the patterns</param>
        /// <param name="numOfNeighbours">size of the neighbourhood</param>
        /// <param name="stateSpace">size of the state space, 2 = binary</param>
        /// <returns></returns>
        public static CellularAutomaton NewWolframAutomaton(uint viewedSize, int[] patterns, int[] states, uint numOfNeighbours = 3u,
                                                            uint stateSpace = 2u) {
            Contract.Requires(3 <= viewedSize);
            Contract.Requires(1 < stateSpace);
            var wolframCode = WolframCode(patterns, states, numOfNeighbours, stateSpace);
            Rule wolframRule = NewWolframRule(wolframCode);
            return new WolframAutomaton(wolframRule, (int) stateSpace, viewedSize);
        }

        /// <summary>
        /// Get a new pattern-rule-based automaton instance, based on the given patterns and corresponding states, 
        /// for a two-dimensional CA
        /// </summary>
        /// <param name="size"></param>
        /// <param name="patterns">the patterns of the rule concatenated into one array</param>
        /// <param name="states">the states correlating to each of the patterns</param>
        /// <param name="numOfNeighbours">size of the neighbourhood</param>
        /// <param name="stateSpace"></param>
        /// <returns></returns>
        public static CellularAutomaton NewPatternAutomaton(uint size, int[] patterns, int[] states, uint numOfNeighbours = 3u,
                                                            uint stateSpace = 2u) ]]></source>
</chunk>
<method name="NewPatternAutomaton" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="600006b" module="AutomaTones.exe"><hits><hit index="0" value="1"/>
<hit index="1" value="1"/>
<hit index="2" value="1"/>
<hit index="3" value="1"/>
<hit index="4" value="1"/>
<hit index="5" value="1"/>
<hit index="7" value="1"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="4" total="4" coveredRatio="1"/>
</method>
<chunk hits="1" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(3 <= size);
            Contract.Requires(1 < stateSpace);
            ]]></source>
</chunk>
<chunk hits="1" offset="0001" domain="userortestcode"><source><![CDATA[var wolframCode = WolframCode(patterns, states, numOfNeighbours, stateSpace);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="000c" domain="userortestcode"><source><![CDATA[Rule wolframRule = NewWolframRule(wolframCode);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="1" offset="0014" domain="userortestcode"><source><![CDATA[return new CellularAutomaton(1, size, wolframRule);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="1" offset="0022" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Get a new Wolfram Rule instance (for one-dimensional use).
        /// </summary>
        /// <param name="wolframCode"></param>
        /// <param name="stateSpace">MUST be >= 2</param>
        /// <returns>Wolfram CA</returns>
        public static Rule NewWolframRule(int[] wolframCode, uint stateSpace = 2u) ]]></source>
</chunk>
<method name="NewWolframRule" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="600006c" module="AutomaTones.exe"><hits><hit index="0" value="2"/>
<hit index="1" value="2"/>
<hit index="3" value="2"/>
<hit index="4" value="2"/>
<hit index="6" value="2"/>
<hit index="8" value="2"/>
<hit index="9" value="2"/>
<hit index="10" value="2"/>
<hit index="11" value="2"/>
<hit index="12" value="2"/>
<hit index="13" value="2"/>
<hit index="14" value="2"/>
<hit index="15" value="2"/>
<hit index="16" value="6"/>
<hit index="17" value="6"/>
<hit index="19" value="6"/>
<hit index="20" value="6"/>
<hit index="21" value="6"/>
<hit index="22" value="6"/>
<hit index="23" value="6"/>
<hit index="24" value="6"/>
<hit index="25" value="6"/>
<hit index="26" value="6"/>
<hit index="27" value="12"/>
<hit index="28" value="8"/>
<hit index="29" value="2"/>
<hit index="30" value="6"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="6" total="6" coveredRatio="1"/>
</method>
<chunk hits="2" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != wolframCode);
            Contract.Requires(1 < stateSpace);
            ]]></source>
</chunk>
<chunk hits="2" offset="0001" domain="userortestcode"><source><![CDATA[WolframRule wolframRule = new WolframRule(1, WolframRule, wolframCode);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

            // Setup the coordinates for the neighbours which the rule uses 
            ]]></source>
</chunk>
<chunk hits="2" offset="0015" domain="userortestcode"><source><![CDATA[var neighbourhood = new[] {-1, 0, 1};]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="6" offset="002a" domain="userortestcode"><source><![CDATA[foreach]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ (]]></source>
</chunk>
<chunk hits="6" offset="0033" domain="userortestcode"><source><![CDATA[int n]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="24" offset="0055" domain="userortestcode"><source><![CDATA[in]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="6" offset="002b" domain="userortestcode"><source><![CDATA[neighbourhood]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="12" offset="0039" domain="userortestcode"><source><![CDATA[wolframRule.AddNeighbour(n);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2" offset="0063" domain="userortestcode"><source><![CDATA[return wolframRule;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2" offset="0067" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Get a new WolframRule instance - for two-dimensional pattern-based CA).
        /// </summary>
        /// <param name="wolframCode"></param>
        /// <param name="stateSpace">MUST be >= 2</param>
        /// <returns>Wolfram CA</returns>
        [PexMethod]
        public static Rule NewPatternRule(int[] wolframCode, uint stateSpace = 2u) ]]></source>
</chunk>
<method name="NewPatternRule" namespace="AutomaTones.Model.Automaton_Model.RuleLib" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata" typeName="WolframAutomata" token="600006d" module="AutomaTones.exe"><hits><hit index="0" value="2"/>
<hit index="1" value="2"/>
<hit index="3" value="2"/>
<hit index="4" value="2"/>
<hit index="6" value="2"/>
<hit index="8" value="2"/>
<hit index="9" value="2"/>
<hit index="11" value="2"/>
<hit index="12" value="2"/>
<hit index="13" value="2"/>
<hit index="14" value="2"/>
<hit index="15" value="2"/>
<hit index="16" value="2"/>
<hit index="17" value="2"/>
<hit index="18" value="2"/>
<hit index="19" value="2"/>
<hit index="20" value="2"/>
<hit index="21" value="2"/>
<hit index="22" value="2"/>
<hit index="24" value="2"/>
<hit index="25" value="2"/>
<hit index="26" value="2"/>
<hit index="27" value="2"/>
<hit index="28" value="2"/>
<hit index="29" value="2"/>
<hit index="30" value="2"/>
<hit index="31" value="2"/>
<hit index="32" value="2"/>
<hit index="34" value="2"/>
<hit index="35" value="2"/>
<hit index="36" value="2"/>
<hit index="37" value="2"/>
<hit index="38" value="2"/>
<hit index="39" value="2"/>
<hit index="40" value="2"/>
<hit index="41" value="2"/>
<hit index="42" value="2"/>
<hit index="43" value="2"/>
<hit index="44" value="2"/>
<hit index="45" value="2"/>
<hit index="47" value="2"/>
<hit index="48" value="2"/>
<hit index="49" value="2"/>
<hit index="50" value="2"/>
<hit index="51" value="2"/>
<hit index="52" value="2"/>
<hit index="53" value="2"/>
<hit index="54" value="2"/>
<hit index="55" value="2"/>
<hit index="57" value="2"/>
<hit index="58" value="2"/>
<hit index="59" value="2"/>
<hit index="60" value="2"/>
<hit index="61" value="2"/>
<hit index="62" value="2"/>
<hit index="63" value="2"/>
<hit index="64" value="2"/>
<hit index="65" value="2"/>
<hit index="66" value="2"/>
<hit index="67" value="2"/>
<hit index="68" value="2"/>
<hit index="70" value="2"/>
<hit index="71" value="2"/>
<hit index="72" value="2"/>
<hit index="73" value="2"/>
<hit index="74" value="2"/>
<hit index="75" value="2"/>
<hit index="76" value="2"/>
<hit index="77" value="2"/>
<hit index="78" value="2"/>
<hit index="80" value="2"/>
<hit index="81" value="2"/>
<hit index="82" value="2"/>
<hit index="83" value="2"/>
<hit index="84" value="2"/>
<hit index="85" value="2"/>
<hit index="86" value="2"/>
<hit index="87" value="2"/>
<hit index="88" value="2"/>
<hit index="89" value="2"/>
<hit index="90" value="2"/>
<hit index="91" value="2"/>
<hit index="93" value="2"/>
<hit index="94" value="2"/>
<hit index="95" value="2"/>
<hit index="96" value="2"/>
<hit index="97" value="2"/>
<hit index="98" value="2"/>
<hit index="99" value="2"/>
<hit index="100" value="2"/>
<hit index="101" value="2"/>
<hit index="102" value="16"/>
<hit index="103" value="16"/>
<hit index="104" value="16"/>
<hit index="105" value="16"/>
<hit index="106" value="16"/>
<hit index="107" value="32"/>
<hit index="108" value="18"/>
<hit index="109" value="2"/>
<hit index="110" value="16"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="6" total="6" coveredRatio="1"/>
</method>
<chunk hits="2" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != wolframCode);
            Contract.Requires(1 < stateSpace);
            ]]></source>
</chunk>
<chunk hits="2" offset="0001" domain="userortestcode"><source><![CDATA[WolframRule wolframRule = new WolframRule(2, WolframRule, wolframCode);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

            // Setup the coordinates for the neighbours which the rule uses 
            ]]></source>
</chunk>
<chunk hits="2" offset="0015" domain="userortestcode"><source><![CDATA[var neighbourhood = new[] {
                                          new[] {-1, 1}, new[] {0, 1}, new[] {1, 1}, new[] {1, 0},
                                          new[] {1, -1}, new[] {0, -1}, new[] {-1, -1}, new[] {-1, 0}
                                      };]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="8" offset="00cc" domain="userortestcode"><source><![CDATA[foreach]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ (]]></source>
</chunk>
<chunk hits="16" offset="00d5" domain="userortestcode"><source><![CDATA[var n]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="56" offset="00e9" domain="userortestcode"><source><![CDATA[in]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="8" offset="00cd" domain="userortestcode"><source><![CDATA[neighbourhood]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[) ]]></source>
</chunk>
<chunk hits="32" offset="00db" domain="userortestcode"><source><![CDATA[wolframRule.AddNeighbour(n);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2" offset="00f7" domain="userortestcode"><source><![CDATA[return wolframRule;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2" offset="00fb" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Demo game Wolfram automaton in the console.
        /// Press a key + return to evolve.
        /// </summary>
        [PexMethod]
        public static void WolframDemo(uint rule, int generations) {
            CellularAutomaton wolframAutomaton = NewWolframAutomaton(70, rule);
//            wolframAutomaton[35] = 1;
            Console.WriteLine("Wolfram elementary automaton using Rule "+rule);
            while (generations-- > 0) {
                Console.Write(wolframAutomaton);
                wolframAutomaton.Evolve();
            }
                Console.Read();
        }
    }
}]]></source>
</chunk>
</document>
<document src="C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Tools\Math.cs" renderPrefix="s3"><chunk hits="-1" domain="unknown"><source><![CDATA[using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

namespace AutomaTones.Model.Tools {
    /// <author>Anders Øland / anoe.itu.dk</author>
    /// <summary>
    /// A few mathematical tool medthods.
    /// </summary>
    public static class Math {
        /// <summary>
        /// Converts unsigned integer to any base.
        /// NOTE: result is given in an array of int's - so eg. hex numbers are represented by digits of 0-15
        /// </summary>
        /// <param name="intNum"></param>
        /// <param name="baseVal"></param>
        /// <param name="digits">specific number of digits for result (optional)</param>
        /// <returns></returns>
        public static int[] DecimalToBase(uint intNum, uint baseVal, uint digits = 0u) ]]></source>
</chunk>
<method name="DecimalToBase" namespace="AutomaTones.Model.Tools" type="AutomaTones.Model.Tools.Math" typeName="Math" token="6000063" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
<hit index="2" value="2400"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="2" total="2" coveredRatio="1"/>
</method>
<chunk hits="2400" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(0 <= intNum && 0 < baseVal);
            Contract.Ensures(Contract.ForAll(Contract.Result<int[]>(), n => 0 <= n && baseVal > n));
            Contract.Ensures(digits <= Contract.Result<int[]>().Length);
            ]]></source>
</chunk>
<chunk hits="2400" offset="0001" domain="userortestcode"><source><![CDATA[return DecimalToBase((ulong) intNum, baseVal, digits);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2400" offset="000d" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Converts unsigned long to any base.
        /// NOTE: result is given in an array of int's - so eg. hex numbers are represented by digits of 0-15
        /// </summary>
        /// <param name="longNum"></param>
        /// <param name="baseVal"></param>
        /// <param name="digits">specific number of digits for result (optional)</param>
        /// <returns></returns>
        [Pure] // Tagged as pure since its being called from other contracts which I dont want to loosen 
        public static int[] DecimalToBase(ulong longNum, uint baseVal, uint digits = 0u) ]]></source>
</chunk>
<method name="DecimalToBase" namespace="AutomaTones.Model.Tools" type="AutomaTones.Model.Tools.Math" typeName="Math" token="6000064" module="AutomaTones.exe"><hits><hit index="0" value="2405"/>
<hit index="1" value="2405"/>
<hit index="3" value="2405"/>
<hit index="4" value="2498"/>
<hit index="5" value="2498"/>
<hit index="6" value="2498"/>
<hit index="7" value="2498"/>
<hit index="8" value="4996"/>
<hit index="9" value="2498"/>
<hit index="10" value="2405"/>
<hit index="11" value="222"/>
<hit index="12" value="222"/>
<hit index="13" value="222"/>
<hit index="14" value="444"/>
<hit index="15" value="2627"/>
<hit index="16" value="2627"/>
<hit index="17" value="2627"/>
<hit index="18" value="5254"/>
<hit index="19" value="2405"/>
<hit index="20" value="2405"/>
<hit index="21" value="2405"/>
<hit index="22" value="2498"/>
<hit index="23" value="222"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="10" total="10" coveredRatio="1"/>
</method>
<chunk hits="2405" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(0 <= longNum && 0 < baseVal);
            Contract.Ensures(digits <= Contract.Result<int[]>().Length);
            ]]></source>
</chunk>
<chunk hits="2405" offset="0001" domain="userortestcode"><source><![CDATA[var result = new LinkedList<int>();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="4903" offset="001d" domain="userortestcode"><source><![CDATA[while (longNum > 0)]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="2498" offset="0009" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="2498" offset="000a" domain="userortestcode"><source><![CDATA[result.AddLast((int) (longNum % baseVal));]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="7494" offset="0016" domain="userortestcode"><source><![CDATA[longNum /= baseVal;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2498" offset="001c" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="3071" offset="0030" domain="userortestcode"><source><![CDATA[while (digits > result.Count)]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="222" offset="0028" domain="userortestcode"><source><![CDATA[result.AddLast(0);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2405" offset="003f" domain="userortestcode"><source><![CDATA[return result.ToArray();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2405" offset="0048" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// Converts n digits of any base to decimal.
        /// </summary>
        /// <param name="baseNum"></param>
        /// <param name="baseVal"></param>
        /// <returns></returns>
        [Pure] // Tagged as pure since its being called from other contracts which I dont want to loosen 
        public static uint BaseToDecimal(int[] baseNum, uint baseVal) ]]></source>
</chunk>
<method name="BaseToDecimal" namespace="AutomaTones.Model.Tools" type="AutomaTones.Model.Tools.Math" typeName="Math" token="6000065" module="AutomaTones.exe"><hits><hit index="0" value="2403"/>
<hit index="1" value="2403"/>
<hit index="3" value="2403"/>
<hit index="4" value="2403"/>
<hit index="5" value="2403"/>
<hit index="6" value="2403"/>
<hit index="7" value="2403"/>
<hit index="8" value="2403"/>
<hit index="9" value="2403"/>
<hit index="11" value="2403"/>
<hit index="12" value="2403"/>
<hit index="13" value="2403"/>
<hit index="14" value="2403"/>
<hit index="15" value="2403"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="5" total="5" coveredRatio="1"/>
</method>
<chunk hits="4806" offset="0014" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != baseNum);
            Contract.Requires(0 < baseNum.Length);
            Contract.Requires(0 < baseVal);
            ]]></source>
</chunk>
<chunk hits="4806" offset="0015" domain="userortestcode"><source><![CDATA[return (uint) baseNum.Select((t, i) => ]]></source>
</chunk>
<method name="&lt;BaseToDecimal&gt;b__0" namespace="AutomaTones.Model.Tools" type="AutomaTones.Model.Tools.Math+&lt;&gt;c__DisplayClass1" typeName="Math+&lt;&gt;c__DisplayClass1" token="6000220" module="AutomaTones.exe"><hits><hit index="0" value="7209"/>
<hit index="1" value="7209"/>
<hit index="2" value="7209"/>
<hit index="3" value="7209"/>
<hit index="4" value="7209"/>
<hit index="5" value="7209"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="2" total="2" coveredRatio="1"/>
</method>
<chunk hits="7209" offset="0000" domain="userortestcode"><source><![CDATA[(t * (int) System.Math.Pow(baseVal, baseNum.Length - i - 1))]]></source>
</chunk>
<chunk hits="4806" offset="0015" domain="userortestcode"><source><![CDATA[).Sum();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2403" offset="0034" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
    }
}]]></source>
</chunk>
</document>
<document src="C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Automaton Model\Rule.cs" renderPrefix="s4"><chunk hits="-1" domain="unknown"><source><![CDATA[using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.Automaton_Model {
    /// <author>Anders Øland / anoe@itu.dk</author>
    /// <summary>
    ///   A rule defining how a cell evolves.
    ///   The rule decides a cells next state based on the current state of its neighbours.
    ///   Each rule defines its own neighbourhood.
    ///   The processing is done by a RuleDelegate (which may be a multicast delegate).
    /// </summary>
    [PexClass]
    [Serializable]
    public class Rule {
        /// <summary>
        ///   The number of dimensions this rule work in; MUST match the dimensions of the automaton.
        /// </summary>
        protected internal uint Dimensions { get; private set; }

        /// <summary>
        ///   The delegate type used for the methods which perform the actual rule processing.
        /// </summary>
        /// <param name = "cell">The cell to be processed</param>
        /// <param name="statesOfNeighbours">The states of the cells neighbours</param>
        /// <param name="optional">optional parameters for specialized rules</param>
        /// <returns></returns>
        public delegate int RuleDelegate(
            Cell cell, ref IEnumerable<StateAtCoordinate> statesOfNeighbours, params int[] optional);

        /// <summary>
        ///   The concrete RuleDelagate used by this Rule to process the next state of a cell
        ///   based on the states of the cells in its neighbourghood.
        /// </summary>
        public RuleDelegate MyRuleDelegate { get; set; }

        ]]></source>
</chunk>
<method name=".ctor" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule" typeName="Rule" token="60001f9" module="AutomaTones.exe"><hits><hit index="0" value="4"/>
<hit index="1" value="4"/>
<hit index="3" value="4"/>
<hit index="4" value="4"/>
<hit index="5" value="4"/>
<hit index="6" value="4"/>
<hit index="7" value="4"/>
<hit index="8" value="4"/>
<hit index="9" value="4"/>
<hit index="10" value="4"/>
<hit index="11" value="4"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="5" total="5" coveredRatio="1"/>
</method>
<chunk hits="4" offset="0000" domain="userortestcode"><source><![CDATA[private List<Position> _neighbourhood = new List<Position>();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   The coordinates of the neighbouring cells to be used when this rule is applied.
        ///   Subject cell is always [0 ,0] (in a 2-dim. grid.) and eg. the left neighbnour is [-1, 0]
        /// </summary>
        public List<Position> Neighbourhood {
            get ]]></source>
</chunk>
<method name="get_Neighbourhood" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule" typeName="Rule" token="60001f7" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="2400" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="2400" offset="0001" domain="userortestcode"><source><![CDATA[return _neighbourhood;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="2400" offset="000a" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            protected internal set {
                Contract.Requires(null != value);
                Contract.Requires(Contract.ForAll<Position>(value, n => Dimensions == n.Coord.Length));
                Contract.Ensures(Neighbourhood == value);
                _neighbourhood = value;
            }
        }

        /// <summary>
        ///   For storing coordinates of (neighbouring) cells.
        ///   Explicit conversions to and from int[] are supported.
        /// </summary>
        [Serializable]
        public struct Position {
            private int[] _coord;

            public int[] Coord {
                get ]]></source>
</chunk>
<method name="get_Coord" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule+Position" typeName="Rule+Position" token="6000203" module="AutomaTones.exe"><hits><hit index="0" value="21600"/>
<hit index="1" value="21600"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="21600" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="21600" offset="0001" domain="userortestcode"><source><![CDATA[return _coord;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="21600" offset="000a" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                internal set ]]></source>
</chunk>
<method name="set_Coord" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule+Position" typeName="Rule+Position" token="6000204" module="AutomaTones.exe"><hits><hit index="0" value="7222"/>
<hit index="1" value="7222"/>
<hit index="2" value="7222"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="7222" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                    Contract.Requires(null != value);
                    Contract.Requires(0 < value.Length);
                    Contract.Ensures(_coord.Equals(value));
                    ]]></source>
</chunk>
<chunk hits="7222" offset="0001" domain="userortestcode"><source><![CDATA[_coord = value;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="14444" offset="0008" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            }

            public Position(params int[] coord)
                : this() {
                Contract.Requires(null != coord);
                Contract.Requires(0 < coord.Length);
                Contract.Ensures(null != coord & this.Coord == coord);
                Coord = coord;
            }

            // explicit conversion from Position to int[], useful for clients.
            public static explicit operator int[](Position p) {
                Contract.Requires(null != p.Coord);
                Contract.Ensures(Contract.ForAll(0, p.Coord.Length,
                                                 i => p.Coord[i] == Contract.Result<int[]>()[i]));
                return p.Coord.ToArray();
            }

            // explicit conversion from int[] to Position, useful for clients.
            public static explicit operator Position(int[] c) ]]></source>
</chunk>
<method name="op_Explicit" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule+Position" typeName="Rule+Position" token="6000207" module="AutomaTones.exe"><hits><hit index="0" value="7222"/>
<hit index="1" value="7222"/>
<hit index="2" value="7222"/>
<hit index="3" value="7222"/>
<hit index="4" value="7222"/>
<hit index="5" value="7222"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="2" total="2" coveredRatio="1"/>
</method>
<chunk hits="7222" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                Contract.Requires(null != c);
                Contract.Requires(0 < c.Length);
                Contract.Ensures(Contract.ForAll(0, c.Length,
                                                 i => c[i] == Contract.Result<Position>().Coord[i]));
                ]]></source>
</chunk>
<chunk hits="7222" offset="0001" domain="userortestcode"><source><![CDATA[return new Position { Coord = (int[])c.Clone() };]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="7222" offset="0020" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

            /// <summary>
            /// Pracical + operator when deciding actual coordinates of neighbours 
            /// (relative to the subject/center cell) 
            /// </summary>
            /// <param name="left"></param>
            /// <param name="right"></param>
            /// <returns></returns>
            public static int[] operator +(Position left, int[] right) ]]></source>
</chunk>
<method name="op_Addition" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule+Position" typeName="Rule+Position" token="6000208" module="AutomaTones.exe"><hits><hit index="0" value="7200"/>
<hit index="1" value="7200"/>
<hit index="2" value="7200"/>
<hit index="3" value="7200"/>
<hit index="5" value="7200"/>
<hit index="6" value="7200"/>
<hit index="7" value="7200"/>
<hit index="8" value="7200"/>
<hit index="9" value="7200"/>
<hit index="10" value="7200"/>
<hit index="11" value="7200"/>
<hit index="12" value="7200"/>
<hit index="13" value="7200"/>
<hit index="14" value="7200"/>
<hit index="15" value="7200"/>
<hit index="16" value="14400"/>
<hit index="17" value="7200"/>
<hit index="18" value="7200"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="5" total="5" coveredRatio="1"/>
</method>
<chunk hits="7200" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                Contract.Requires(left.Coord.Length == right.Length);
                ]]></source>
</chunk>
<chunk hits="7200" offset="0001" domain="userortestcode"><source><![CDATA[int[] result = new int[left.Coord.Length];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                for (]]></source>
</chunk>
<chunk hits="7200" offset="0010" domain="userortestcode"><source><![CDATA[int i = 0;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="28800" offset="0028" domain="userortestcode"><source><![CDATA[i < right.Length]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[; ]]></source>
</chunk>
<chunk hits="21600" offset="0024" domain="userortestcode"><source><![CDATA[i++]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[)
                    ]]></source>
</chunk>
<chunk hits="7200" offset="0014" domain="userortestcode"><source><![CDATA[result[i] = right[i] + left.Coord[i];]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="7200" offset="0032" domain="userortestcode"><source><![CDATA[return result;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="7200" offset="0036" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

            /// <summary>
            ///   Indicates whether this instance and a specified object are equal.
            ///   Accepts int[] as well as Position.
            /// </summary>
            /// <returns>
            ///   true if <paramref name = "obj" /> is either Position or int[] and represent the same coordinate; otherwise, false.
            /// </returns>
            /// <param name = "obj">Another object to compare to. </param>
            /// <filterpriority>2</filterpriority>
            public override bool Equals(object obj) {
                Contract.Requires(null != obj);
                Contract.Requires((obj is Position & ((Position)obj).Coord.Length > 0 || (obj is int[] & ((int[])obj).Length > 0)));
                if (!(obj is Position || obj is int[])) return false;
                Position p;
                if (obj is Position) p = (Position)obj;
                else {
                    int[] tmp = (int[])obj;
                    p = (Position)tmp;
                }
                return p.Coord.SequenceEqual(_coord);
            }

            public override int GetHashCode() {
                return (_coord != null ? _coord.GetHashCode() : 0);
            }
        }

        /// <summary>
        /// A state associated with a given coordinate. Intended for use with neighbours and rules.
        /// Thus the coordinate must be relative to point [0,0.., 0] 
        /// </summary>
        public struct StateAtCoordinate {
            [NonSerialized]
            private Position _position;

            // ReSharper disable MemberHidesStaticFromOuterClass
            public Position Position {
                // ReSharper restore MemberHidesStaticFromOuterClass
                get { return _position; }
                internal set ]]></source>
</chunk>
<method name="set_Position" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule+StateAtCoordinate" typeName="Rule+StateAtCoordinate" token="600020c" module="AutomaTones.exe"><hits><hit index="0" value="7200"/>
<hit index="1" value="7200"/>
<hit index="2" value="7200"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="7200" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                    Contract.Requires(0 < value.Coord.Length);
                    Contract.Ensures(_position.Equals(value));
                    ]]></source>
</chunk>
<chunk hits="7200" offset="0001" domain="userortestcode"><source><![CDATA[_position = value;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                ]]></source>
</chunk>
<chunk hits="14400" offset="0008" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            }

            public int State { get; internal set; }

            public StateAtCoordinate(Position pos, int state)
                : this() {
                Contract.Requires(0 < pos.Coord.Length);
                Position = pos;
                State = state;
            }
        }

        /// <summary>
        ///   Construct a Rule for a celluar automaton with the given dimensions.
        /// </summary>
        /// <param name = "dimensions"></param>
        /// <param name = "ruleDelegate">The rule function</param>
        ]]></source>
</chunk>
<chunk hits="8" offset="000b" domain="userortestcode"><source><![CDATA[public Rule(uint dimensions, RuleDelegate ruleDelegate)]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="4" offset="0012" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="4" offset="0013" domain="userortestcode"><source><![CDATA[Dimensions = dimensions;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="4" offset="001b" domain="userortestcode"><source><![CDATA[MyRuleDelegate = ruleDelegate;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="4" offset="0023" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Apply the method in the instance's RuleDelegate to the given cell.
        /// </summary>
        /// <param name="subject"></param>
        /// <param name = "cellularAutomaton"></param>
        /// <param name="optional">Optional parameters for specialized rules</param>
        /// <returns>The next state of the cell based on current state of its neighbourhood</returns>
        [PexMethod]
        public virtual int ApplyRule(int[] subject, CellularAutomaton cellularAutomaton, params int[] optional) ]]></source>
</chunk>
<method name="ApplyRule" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule" typeName="Rule" token="60001fa" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
<hit index="3" value="2400"/>
<hit index="4" value="2400"/>
<hit index="5" value="2400"/>
<hit index="6" value="2400"/>
<hit index="7" value="2400"/>
<hit index="8" value="2400"/>
<hit index="9" value="2400"/>
<hit index="10" value="2400"/>
<hit index="12" value="2400"/>
<hit index="13" value="2400"/>
<hit index="14" value="2400"/>
<hit index="15" value="2400"/>
<hit index="16" value="2400"/>
<hit index="17" value="2400"/>
<hit index="18" value="2400"/>
<hit index="19" value="2400"/>
<hit index="20" value="4800"/>
<hit index="21" value="2400"/>
<hit index="22" value="2400"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="7" total="7" coveredRatio="1"/>
</method>
<chunk hits="4800" offset="0014" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != subject);
            Contract.Requires(0 < Neighbourhood.Count);
            Contract.Ensures(cellularAutomaton.GetCell(subject).State.SpaceMin <= Contract.Result<int>());
            Contract.Ensures(cellularAutomaton.GetCell(subject).State.SpaceMax >= Contract.Result<int>());
            ]]></source>
</chunk>
<chunk hits="4800" offset="0015" domain="userortestcode"><source><![CDATA[IEnumerable<StateAtCoordinate> statesOfNeighbours =
                (from n in Neighbourhood
                 select ]]></source>
</chunk>
<method name="&lt;ApplyRule&gt;b__1" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule+&lt;&gt;c__DisplayClass2" typeName="Rule+&lt;&gt;c__DisplayClass2" token="600022b" module="AutomaTones.exe"><hits><hit index="0" value="7200"/>
<hit index="1" value="7200"/>
<hit index="2" value="7200"/>
<hit index="3" value="7200"/>
<hit index="4" value="7200"/>
<hit index="5" value="7200"/>
<hit index="6" value="7200"/>
<hit index="7" value="7200"/>
<hit index="8" value="7200"/>
<hit index="9" value="7200"/>
<hit index="10" value="7200"/>
<hit index="11" value="7200"/>
<hit index="12" value="7200"/>
<hit index="13" value="7200"/>
<hit index="14" value="7200"/>
<hit index="15" value="14400"/>
<hit index="16" value="7200"/>
<hit index="17" value="7200"/>
<hit index="18" value="7200"/>
<hit index="19" value="14400"/>
<hit index="20" value="7200"/>
<hit index="21" value="7200"/>
<hit index="22" value="7200"/>
<hit index="23" value="14400"/>
<hit index="24" value="7200"/>
<hit index="25" value="7200"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="9" total="9" coveredRatio="1"/>
</method>
<chunk hits="7200" offset="0000" domain="userortestcode"><source><![CDATA[new StateAtCoordinate {
                     Position = (Position)n.Coord,
                     State = cellularAutomaton.GetCell(n + subject).State.CurrentState
                 }]]></source>
</chunk>
<chunk hits="4800" offset="0015" domain="userortestcode"><source><![CDATA[);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2400" offset="002d" domain="userortestcode"><source><![CDATA[return DispatchToDelegate(cellularAutomaton.GetCell(subject), statesOfNeighbours, optional);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2400" offset="0049" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// This method provides a simple yet not perfect workaround for enforcing contracts on delegates.
        /// It simply wraps the invocation of the delegate with pre- and postconditions.
        /// The postcondition focuses on validating the immutability of the forwarded data.
        /// Primarily to ensure that if we're dealine with a multicast delegate - 
        /// none of its members screw things up for the others.
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="statesOfNeighbours">Call by reference so we can check in the postcondition if it has been modified</param>
        /// <param name="optional"></param>
        /// <returns></returns>
        private int DispatchToDelegate(Cell cell, IEnumerable<StateAtCoordinate> statesOfNeighbours,
                                       params int[] optional) ]]></source>
</chunk>
<method name="DispatchToDelegate" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule" typeName="Rule" token="60001fb" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
<hit index="2" value="2400"/>
<hit index="3" value="2400"/>
<hit index="4" value="2400"/>
<hit index="5" value="2400"/>
<hit index="6" value="4800"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="3" total="3" coveredRatio="1"/>
</method>
<chunk hits="2400" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != cell);
            Contract.Requires(null != cell.State);
            Contract.Requires(0 < Neighbourhood.Count);
            Contract.Requires(Neighbourhood.Count == statesOfNeighbours.Count());
            Contract.Requires(Contract.ForAll(statesOfNeighbours, s => Dimensions == s.Position.Coord.Length));
            Contract.Ensures(Contract.OldValue(cell) == cell);
            Contract.Ensures(cell.State.SpaceMin <= Contract.Result<int>());
            Contract.Ensures(cell.State.SpaceMax >= Contract.Result<int>());
            ]]></source>
</chunk>
<chunk hits="2400" offset="0001" domain="userortestcode"><source><![CDATA[return MyRuleDelegate(cell, ref statesOfNeighbours, optional);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="7200" offset="0013" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Clear the neighbourhood for this rule.
        /// </summary>
        protected internal void ClearNeighbourhood() {
            _neighbourhood = new List<Position>();
        }

        /// <summary>
        ///   Add a neighbour with the gicen coordinats to the neighbourhood.
        ///   Note: if it is already in the neighbourhood it will not be added again.
        /// </summary>
        /// <param name = "coord"></param>
        protected internal void AddNeighbour(params int[] coord) ]]></source>
</chunk>
<method name="AddNeighbour" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Rule" typeName="Rule" token="60001fd" module="AutomaTones.exe"><hits><hit index="0" value="22"/>
<hit index="1" value="22"/>
<hit index="2" value="22"/>
<hit index="3" value="22"/>
<hit index="4" value="22"/>
<hit index="5" value="22"/>
<hit index="6" value="22"/>
<hit index="7" value="44"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="3" total="3" coveredRatio="1"/>
</method>
<chunk hits="22" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(Dimensions == coord.Length);
            Contract.Ensures(Neighbourhood.Contains((Position)coord));
            ]]></source>
</chunk>
<chunk hits="22" offset="0001" domain="userortestcode"><source><![CDATA[_neighbourhood.Add((Position)coord);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="66" offset="0013" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        [ContractInvariantMethod]
// ReSharper disable UnusedMember.Local
        private void ObjInvariant() {
// ReSharper restore UnusedMember.Local
            Contract.Invariant(0 < Dimensions);
        }
    }

    /// <author>Anders Øland / anoe@itu.dk</author>
    /// <summary>
    /// A specialized rule for use with Wolfram Automata - or other pattern-based rule-type CA's.
    /// </summary>
    [Serializable]
    public class WolframRule : Rule {
        /// <summary>
        /// The Wolfram code for this Wolfram rule.
        /// </summary>
        public int[] WolframCode { get; internal set; }

        ]]></source>
</chunk>
<method name=".ctor" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.WolframRule" typeName="WolframRule" token="6000212" module="AutomaTones.exe"><hits><hit index="0" value="4"/>
<hit index="1" value="4"/>
<hit index="2" value="4"/>
<hit index="3" value="4"/>
<hit index="4" value="4"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="3" total="3" coveredRatio="1"/>
</method>
<chunk hits="4" offset="0000" domain="userortestcode"><source><![CDATA[public WolframRule(uint dimensions, RuleDelegate ruleDelegate, int[] wolframCode)
            : base(dimensions, ruleDelegate)]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="4" offset="0009" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="4" offset="000a" domain="userortestcode"><source><![CDATA[WolframCode = wolframCode;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="4" offset="0012" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        ///   Apply the method in the instance's RuleDelegate to the given cell.
        /// </summary>
        /// <param name="subject"></param>
        /// <param name = "cellularAutomaton"></param>
        /// <param name="optional">Optional parameters for specialized rules</param>
        /// <returns>The next state of the cell based on current state of its neighbourhood</returns>
        public override int ApplyRule(int[] subject, CellularAutomaton cellularAutomaton, params int[] optional) ]]></source>
</chunk>
<method name="ApplyRule" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.WolframRule" typeName="WolframRule" token="6000213" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
<hit index="2" value="2400"/>
<hit index="3" value="2400"/>
<hit index="4" value="2400"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="3" total="3" coveredRatio="1"/>
</method>
<chunk hits="2400" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="2400" offset="0001" domain="userortestcode"><source><![CDATA[return base.ApplyRule(subject, cellularAutomaton, WolframCode);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="2400" offset="0012" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
    }
}]]></source>
</chunk>
</document>
<document src="C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Automaton Model\Cell.cs" renderPrefix="s5"><chunk hits="-1" domain="unknown"><source><![CDATA[using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.Automaton_Model {
    /// <summary>
    /// A cell with a given state decided by one or more rules.
    /// Multiple triggers can be attached to react to different states - by publishing events.
    /// </summary>
    /// <author>Anders Øland / anoe@itu.dk</author>
    [Serializable]
    public class Cell {
        /// <summary>
        /// The state of the cell.
        /// </summary>
        public State State { get; protected internal set; }
        
        /// <summary>
        /// The rule governing the state & evolution of this cell
        /// </summary>
        public Rule Rule { get; protected internal set; }
        
        ]]></source>
</chunk>
<method name=".ctor" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.Cell" typeName="Cell" token="60001c5" module="AutomaTones.exe"><hits><hit index="0" value="116"/>
<hit index="1" value="116"/>
<hit index="3" value="116"/>
<hit index="4" value="116"/>
<hit index="5" value="116"/>
<hit index="6" value="116"/>
<hit index="7" value="116"/>
<hit index="8" value="116"/>
<hit index="9" value="116"/>
<hit index="10" value="116"/>
<hit index="12" value="116"/>
<hit index="13" value="116"/>
<hit index="14" value="116"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="6" total="6" coveredRatio="1"/>
</method>
<chunk hits="116" offset="0000" domain="userortestcode"><source><![CDATA[private HashSet<Trigger> _triggers = new HashSet<Trigger>();]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        /// <summary>
        /// The set of triggers for this cell. May be empty.
        /// </summary>
        public HashSet<Trigger> Triggers {
            get { return _triggers; }
            protected internal set {
                Contract.Requires(null != value);
                Contract.Requires(Contract.ForAll<Trigger>(value, v => null != v));
                Contract.Ensures(Triggers == value);
                _triggers = value;
            }
        }

        /// <summary>
        /// Add a trigger to this cell.
        /// </summary>
        /// <param name="trigger"></param>
        public void AddTrigger(Trigger trigger) {
            Contract.Requires(null != trigger);
            Contract.Ensures(Triggers.Contains(trigger));
            _triggers.Add(trigger);
        }

        /// <summary>
        /// Remove a trigger from this cell.
        /// </summary>
        /// <param name="trigger"></param>
        public void RemoveTrigger(Trigger trigger) {
            Contract.Requires(null != trigger);
            Contract.Ensures(!Triggers.Contains(trigger));
            _triggers.Remove(trigger);
        }

        ]]></source>
</chunk>
<chunk hits="232" offset="000b" domain="userortestcode"><source><![CDATA[public Cell(Rule rule, int stateMin = 0, int stateMax = 1, int stateInit = 0)]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="116" offset="0012" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            Contract.Requires(null != rule);
            Contract.Requires(stateMin < stateMax);
            Contract.Requires(stateMin <= stateInit && stateMax >= stateInit);
            Contract.Ensures(Rule.Equals(rule));
            Contract.Ensures(State.SpaceMin == stateMin && State.SpaceMax == stateMax && State.CurrentState == stateInit);
            ]]></source>
</chunk>
<chunk hits="116" offset="0013" domain="userortestcode"><source><![CDATA[Rule = rule;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="116" offset="001b" domain="userortestcode"><source><![CDATA[State = new State(stateMin, stateMax, stateInit);]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="116" offset="002b" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        [ContractInvariantMethod]
        private void ObjInvariant() {
            Contract.Invariant(null != State);
            Contract.Invariant(null != Rule);
        }
    }
}
]]></source>
</chunk>
</document>
<document src="C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Automaton Model\State.cs" renderPrefix="s6"><chunk hits="-1" domain="unknown"><source><![CDATA[using System;
using System.Diagnostics.Contracts;

namespace AutomaTones.Model.Automaton_Model {
    /// <author>Anders Øland / anoe@itu.dk</author>
    /// <summary>
    /// The state of a cell represented by a discrete value within a given state space.. 
    /// NOTE: Ideally this would be implemented using generics so states could also be decimals.
    /// NOTE: But due to C#'s lack of type constraint options on value types - this was omitted.
    /// </summary>
    [Serializable]
    public class State {
        /// <summary>
        /// The lower boundary of the state space.
        /// </summary>
        public int SpaceMin { get; protected set; }

        /// <summary>
        /// The upper boundary of the state space.
        /// </summary>
        public int SpaceMax { get; protected set; }

        private int _currentState;

        /// <summary>
        /// Current state.
        /// </summary>
        public int CurrentState {
            get ]]></source>
</chunk>
<method name="get_CurrentState" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.State" typeName="State" token="60000a5" module="AutomaTones.exe"><hits><hit index="0" value="7200"/>
<hit index="1" value="7200"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="7200" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="7200" offset="0001" domain="userortestcode"><source><![CDATA[return _currentState;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="7200" offset="000a" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            protected internal set ]]></source>
</chunk>
<method name="set_CurrentState" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.State" typeName="State" token="60000a6" module="AutomaTones.exe"><hits><hit index="0" value="2401"/>
<hit index="1" value="2401"/>
<hit index="2" value="2401"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="2401" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                Contract.Ensures(CurrentState == value);
                ]]></source>
</chunk>
<chunk hits="2401" offset="0001" domain="userortestcode"><source><![CDATA[_currentState = value;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="4802" offset="0008" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        }

        private int _nextState;

        /// <summary>
        /// Next state.
        /// </summary>
        public int NextState {
            get ]]></source>
</chunk>
<method name="get_NextState" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.State" typeName="State" token="60000a7" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="2400" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="2400" offset="0001" domain="userortestcode"><source><![CDATA[return _nextState;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="2400" offset="000a" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            protected internal set ]]></source>
</chunk>
<method name="set_NextState" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.State" typeName="State" token="60000a8" module="AutomaTones.exe"><hits><hit index="0" value="2400"/>
<hit index="1" value="2400"/>
<hit index="2" value="2400"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<chunk hits="2400" offset="0000" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
                Contract.Ensures(NextState == value);
                ]]></source>
</chunk>
<chunk hits="2400" offset="0001" domain="userortestcode"><source><![CDATA[_nextState = value;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="4800" offset="0008" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        }

        /// <summary>
        /// Construct a new State. 
        /// </summary>
        /// <param name="spaceMin"></param>
        /// <param name="spaceMax"></param>
        /// <param name="currentState"></param>
        ]]></source>
</chunk>
<method name=".ctor" namespace="AutomaTones.Model.Automaton_Model" type="AutomaTones.Model.Automaton_Model.State" typeName="State" token="60000a9" module="AutomaTones.exe"><hits><hit index="0" value="116"/>
<hit index="1" value="116"/>
<hit index="2" value="116"/>
<hit index="3" value="116"/>
<hit index="4" value="116"/>
<hit index="5" value="116"/>
<hit index="6" value="116"/>
<hit index="7" value="116"/>
<hit index="8" value="116"/>
</hits>
<coverage domain="userortestcode" unit="block" covered="4" total="4" coveredRatio="1"/>
</method>
<chunk hits="116" offset="0000" domain="userortestcode"><source><![CDATA[public State(int spaceMin = 0, int spaceMax = 1, int currentState = 0)]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[ ]]></source>
</chunk>
<chunk hits="116" offset="0007" domain="userortestcode"><source><![CDATA[{]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="116" offset="0008" domain="userortestcode"><source><![CDATA[SpaceMin = spaceMin;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="116" offset="0010" domain="userortestcode"><source><![CDATA[SpaceMax = spaceMax;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
            ]]></source>
</chunk>
<chunk hits="116" offset="0018" domain="userortestcode"><source><![CDATA[_currentState = currentState;]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[
        ]]></source>
</chunk>
<chunk hits="232" offset="001f" domain="userortestcode"><source><![CDATA[}]]></source>
</chunk>
<chunk hits="-1" domain="unknown"><source><![CDATA[

        [ContractInvariantMethod]
        private void ObjInvariant() {
            Contract.Invariant(SpaceMin < SpaceMax);
            Contract.Invariant(SpaceMin <= _currentState && SpaceMax >= _currentState);
            Contract.Invariant(SpaceMin <= _nextState && SpaceMax >= _nextState);
        }
    }
}]]></source>
</chunk>
</document>
<document src="(no sources available for some parts of AutomaTones)" missing="true"><method name="set_Dimensions" type="AutomaTones.Model.Automaton_Model.Rule" token="60001f4" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_MyRuleDelegate" type="AutomaTones.Model.Automaton_Model.Rule" token="60001f6" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_WolframCode" type="AutomaTones.Model.Automaton_Model.WolframRule" token="6000211" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_Generation" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" token="60001cc" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_Dimensions" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" token="60001c8" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_DimensionSize" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" token="60001ca" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_DimensionSize" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" token="60001c9" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_Dimensions" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" token="60001c7" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_Rule" type="AutomaTones.Model.Automaton_Model.Cell" token="60001c0" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_SpaceMin" type="AutomaTones.Model.Automaton_Model.State" token="60000a2" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_SpaceMax" type="AutomaTones.Model.Automaton_Model.State" token="60000a4" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_State" type="AutomaTones.Model.Automaton_Model.Cell" token="60001be" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_DefaultRule" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" token="60001ce" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="set_ViewedSize" type="AutomaTones.Model.Automaton_Model.WolframAutomaton" token="60001e3" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_ViewedSize" type="AutomaTones.Model.Automaton_Model.WolframAutomaton" token="60001e2" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_State" type="AutomaTones.Model.Automaton_Model.Cell" token="60001bd" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_Rule" type="AutomaTones.Model.Automaton_Model.Cell" token="60001bf" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_WolframCode" type="AutomaTones.Model.Automaton_Model.WolframRule" token="6000210" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name=".ctor" type="AutomaTones.Model.Automaton_Model.Rule+&lt;&gt;c__DisplayClass2" token="600022a" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="2" total="2" coveredRatio="1"/>
</method>
<method name="get_MyRuleDelegate" type="AutomaTones.Model.Automaton_Model.Rule" token="60001f5" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name=".ctor" type="AutomaTones.Model.Automaton_Model.RuleLib.WolframAutomata+&lt;&gt;c__DisplayClass2" token="6000221" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="2" total="2" coveredRatio="1"/>
</method>
<method name="set_State" type="AutomaTones.Model.Automaton_Model.Rule+StateAtCoordinate" token="600020e" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_State" type="AutomaTones.Model.Automaton_Model.Rule+StateAtCoordinate" token="600020d" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_SpaceMax" type="AutomaTones.Model.Automaton_Model.State" token="60000a3" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name="get_SpaceMin" type="AutomaTones.Model.Automaton_Model.State" token="60000a1" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
<method name=".ctor" type="AutomaTones.Model.Tools.Math+&lt;&gt;c__DisplayClass1" token="600021f" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="2" total="2" coveredRatio="1"/>
</method>
<method name="get_Generation" type="AutomaTones.Model.Automaton_Model.CellularAutomaton" token="60001cb" module="AutomaTones.exe"><hits/>
<coverage domain="userortestcode" unit="block" covered="1" total="1" coveredRatio="1"/>
</method>
</document>
</documents>
